package com.totcy.baselibrary.base;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.totcy.baselibrary.base.mvpbase.BasePresenterImpl;
import com.totcy.baselibrary.base.mvpbase.BaseView;
import com.totcy.baselibrary.utils.TUtil;

/**
 * Description
 * <p>
 * <B>MVP模式基本fragment，<br>
 * V:Presenter层处理数据时提供回调给View层的接口interface，此接口继承于{@link BaseView}；<br>
 * T：在此页面中，处理数据所使用的Presenter层，继承自{@link BasePresenterImpl}</B><br>
 * <p>
 *
 * @author : tu
 *         Date: 2017-04-13
 *         Time: 15:49
 */
public abstract class BaseMvpFragment<V extends BaseView,P extends BasePresenterImpl> extends BaseFragment implements BaseView {

    protected P mPresenter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mPresenter = TUtil.getPresenterT(getActivity(), this, 1);
        //实现view
        if (mPresenter != null) {
            //简单页面无需mvp就不用管此方法即可,完美兼容各种实际场景的变通
            mPresenter.attachView((V) this);
        }
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    public P getPresenter() {
        return mPresenter;
    }

    /**
     * 显示加载框
     */
    @Override
    public void showProgress(String message) {

    }

    /**
     * 隐藏加载框
     */
    @Override
    public void dismissProgress() {

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (mPresenter != null) {
            mPresenter.detachView();
            mPresenter.detachModel();
        }
    }
}
